package de.hauschild.orbitvm.vm.instruction.impl.dooble;

import de.hauschild.orbitvm.vm.VM;
import de.hauschild.orbitvm.vm.instruction.impl.AbstractInstruction;

public abstract class AbstractDoubleInstruction extends AbstractInstruction {

  private final int firstArgumentAdress;
  private final int secondArgumentAdress;

  public AbstractDoubleInstruction(final int theInstructionCounter, final int theFirstArgumentAdress,
      final int theSecondArgumentAdress) {
    super(theInstructionCounter);
    firstArgumentAdress = theFirstArgumentAdress;
    secondArgumentAdress = theSecondArgumentAdress;
  }

  @Override
  public void evaluate(final VM vm) {
    vm.getMemory()[getInstructionCounter()] = evaluate(vm.getMemory()[firstArgumentAdress],
        vm.getMemory()[secondArgumentAdress]);
  }

  @Override
  public String toString() {
    return String.format("%d: %s (%d, %d)", getInstructionCounter(), getName(), firstArgumentAdress,
        secondArgumentAdress);
  }

  protected abstract double evaluate(final double firstArgument, final double secondArgument);

  protected abstract String getName();

}
